package scala

import com.google.gson.Gson

import scala.io.Source

object Demo33Json {

  def main(args: Array[String]): Unit = {

    //读取数据
    val students: List[String] = Source.fromFile("data/students.json").getLines().toList

    val gson = new Gson()



    val stus: List[Student1] = students.map(stu => {

      /**
        * classOf[Student] ： scala 中获取类对象的方式
        */

      val student: Student1 = gson.fromJson(stu, classOf[Student1])

      student
    })


    stus.foreach(println)

  }


  case class Student1(id: String, name: String, age: Int, gender: String, clazz: String)

}
